package com.mall.payment.config;

import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConstants;
import com.alipay.api.DefaultAlipayClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;

/**
 * @author: 谢君臣
 * @Date: 2022/7/2-18:08
 * @version: 1.0
 * @function:
 */
@Configuration
@PropertySource("classpath:base.properties")
public class AlipayConfig {

    // 方式一
    @Resource
    private Environment environment;

    // 方式二

    @Value("${alipay.serverUrl}")
    private String serverUrl;
    @Value("${alipay.returnUrl}")
    private String returnUrl;
    @Value("${alipay.appId}")
    private String appId;
    @Value("${alipay.privateKey}")
    private String privateKey;
    private final String format = AlipayConstants.FORMAT_JSON;
    private final String charset = AlipayConstants.CHARSET_UTF8;
    @Value("${alipay.zfbPublicKey}")
    private String alipayPublicKey;
    private final String signType = AlipayConstants.SIGN_TYPE_RSA2;
    @Value("${alipay.notifyUrl}")
    private String notifyUrl;
    @Value("${alipay.sellerId}")
    private String sellerId;


    @Bean
    public AlipayClient alipayClient() {
        //实例化客户端
        AlipayClient alipayClient = new DefaultAlipayClient(
                environment.getProperty("alipay.serverUrl"),
                environment.getProperty("alipay.appId"),
                environment.getProperty("alipay.privateKey"),
                AlipayConstants.FORMAT_JSON,
                AlipayConstants.CHARSET_UTF8,
                environment.getProperty("alipay.zfbPublicKey"),
                AlipayConstants.SIGN_TYPE_RSA2
        );
        return alipayClient;
    }


    public Environment getEnvironment() {
        return environment;
    }

    public String getServerUrl() {
        return serverUrl;
    }

    public String getAppId() {
        return appId;
    }

    public String getPrivateKey() {
        return privateKey;
    }

    public String getFormat() {
        return format;
    }

    public String getCharset() {
        return charset;
    }

    public String getAlipayPublicKey() {
        return alipayPublicKey;
    }

    public String getSignType() {
        return signType;
    }

    public String getNotifyUrl() {
        return notifyUrl;
    }

    public String getSellerId() {
        return sellerId;
    }

    public String getReturnUrl() {
        return returnUrl;
    }

    public void setReturnUrl(String returnUrl) {
        this.returnUrl = returnUrl;
    }
}
